# -*- coding:utf-8 -*-
# @Time: 2020/8/24 17:43
# @Author: liupengfei
# @File: serializers.py
from rest_framework import serializers
from apps.system.serializers import ImagesSerializer
from utils.serializersfield import ImageUploadCharField
from .models import AdornPedia


class AdornPediaSerializer(serializers.ModelSerializer):
    category_text = serializers.CharField(source='category.name', read_only=True)
    thumbnail_arr = ImageUploadCharField(source='thumbnail', read_only=True)
    thumbnail_path = serializers.SerializerMethodField(read_only=True)

    def get_thumbnail_path(self, obj):
        if obj.thumbnail:
            return obj.thumbnail.get_url()
        return ''

    class Meta:
        model = AdornPedia
        fields = '__all__'
